package com.maixun.lib_business_knowledge

import android.app.Application
import com.lmoumou.lib_domian.DomainLauncher
import com.maixun.lib_comment.CommentApplication
import com.maixun.lib_network.base.INetworkRequiredInfo
import com.maixun.lib_network.base.NetworkApi

/**
 * @author：Lmoumou
 * @date：2020/10/16
 */
class KnowledgeApp : CommentApplication() {

    override fun onCreate() {
        super.onCreate()
        NetworkApi.init(object : INetworkRequiredInfo {
            override fun getBaseUrl(): String = "baseUrl"

            override fun getAppVersionName(): String = BuildConfig.VERSION_NAME

            override fun getAppVersionCode(): String = "${BuildConfig.VERSION_CODE}"

            override fun isDebug(): Boolean = BuildConfig.DEBUG

            override fun getApplicationContext(): Application = this@KnowledgeApp
        })

        DomainLauncher.getInstance()
            .addDomain("http://192.168.0.201:8080/v1/", "(蒋建军)")
            .addDomain("http://192.168.0.14:8080/v1/", "(刘纯夫1)")
            .addDomain("https://test-api.chengdumaixun.com/v1/", "测试服务器")
            .addDomain("https://api.chengdumaixun.com/v1/", "(正式服务器)")

        DomainLauncher.getInstance().settingChangeCallback = object :
            DomainLauncher.SettingChangeCallback {
            override fun onDomainChange(domain: String) {
                NetworkApi.init(object : INetworkRequiredInfo {
                    override fun getBaseUrl(): String = domain

                    override fun getAppVersionName(): String = BuildConfig.VERSION_NAME

                    override fun getAppVersionCode(): String = "${BuildConfig.VERSION_CODE}"

                    override fun isDebug(): Boolean = BuildConfig.DEBUG

                    override fun getApplicationContext(): Application = this@KnowledgeApp
                })
            }

            override fun onDomainResChange(domainRes: String) {

            }
        }
    }
}